﻿using System;
using System.IO;
using NUnit.Framework;
using System.Threading;

namespace Twitter.Tests
{
	[TestFixture]
	public class StatusesFixture : TestBase
	{
		[ExpectedException(typeof(ArgumentNullException))]
		[Test]
		public void ShouldThrowIfNullDeleteStatusId()
		{
			TestRun.CreateClient().Statuses.Delete(null);
		}

		[ExpectedException(typeof(ArgumentException))]
		[Test]
		public void ShouldThrowIfEmptyDeleteStatusId()
		{
			TestRun.CreateClient().Statuses.Delete("");
		}

		[Test]
		public void ShouldUpdateStatusAndGetLatest()
		{
			IBotClient client = TestRun.CreateClient();

			string newStatus = Guid.NewGuid().ToString();
			client.Statuses.Update(Guid.NewGuid().ToString());
			client.Statuses.Update(newStatus);

			string updated = client.Statuses.GetLatest().Text;

			Assert.AreEqual(newStatus, updated);
		}

		[Test]
		public void ShouldDeleteStatus()
		{
			IBotClient client = TestRun.CreateClient();

			string status1 = Guid.NewGuid().ToString();
			string status2 = Guid.NewGuid().ToString();
			client.Statuses.Update(status1);
			Thread.Sleep(100);
			client.Statuses.Update(status2);

			Status latest = client.Statuses.GetLatest();

			Assert.AreEqual(status2, latest.Text);

			Assert.IsTrue(client.Statuses.Delete(latest.Id));

			string savedStatus = client.Statuses.GetLatest().Text;

			Assert.AreEqual(status1, savedStatus);
		}
	}
}
